package com.kun.service_edu.controller;


import com.kun.service_edu.entity.EduChapter;
import com.kun.service_edu.entity.vo.chapter.ChapterVo;
import com.kun.service_edu.service.EduChapterService;
import com.kun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-10-04
 */
@RestController
@RequestMapping("/service_edu/edu-chapter")
@CrossOrigin
public class EduChapterController {
    @Autowired
    private EduChapterService chapterService;
    @PostMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable String courseId){
        List<ChapterVo> list= chapterService.getChapterServiceVideoByCourseId(courseId);
        return R.ok().data("allChapterVideo",list);
    }

    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){
        boolean flag= chapterService.save(eduChapter);
        if (flag==true){
            return R.ok();
        }else {
            return R.error();
        }

    }

    @PostMapping("getChapterById/{ChapterId}")
    public R getChapterById(@PathVariable String ChapterId){
        EduChapter eduChapter = chapterService.getById(ChapterId);
        return R.ok().data("chapter",eduChapter);
    }
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){


        boolean flag=chapterService.updateById(eduChapter);
        if (flag==true){
            return R.ok();
        }else {
            return R.error();
        }
    }
    @PostMapping("delChapterById/{ChapterId}")
    public R delChapterById(@PathVariable String ChapterId){
        boolean flag=chapterService.delChapter(ChapterId);
        if (flag==true){
            return R.ok();
        }else {
            return R.error();
        }
    }
}

